﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ReservationCtrlService;
using ModelLayer;

public partial class User_Reservations : System.Web.UI.Page
{
	private ReservationCtrlClient reservationCtrl;

	protected void Page_Load(object sender, EventArgs e)
	{
		reservationCtrl = new ReservationCtrlClient();
		Reservation[] reservations = reservationCtrl.getReservations();

		TableHeaderRow headerRow = new TableHeaderRow();
		headerRow.Cells.AddRange(getHeaderCells());
		ReservationsTable.Rows.Add(headerRow);

		foreach (Reservation reservation in reservations)
		{
			TableRow row = new TableRow();
			TableCell idCell = new TableCell();
			idCell.Text = reservation.Id.ToString();
			row.Cells.Add(idCell);
			TableCell nameCell = new TableCell();
			nameCell.Text = reservation.Name;
			row.Cells.Add(nameCell);
			TableCell phoneNrCell = new TableCell();
			phoneNrCell.Text = reservation.PhoneNr;
			row.Cells.Add(phoneNrCell);
			TableCell ticketIdCell = new TableCell();
			ticketIdCell.Text = reservation.Ticket.id.ToString();
			row.Cells.Add(ticketIdCell);
			ReservationsTable.Rows.Add(row);
		}
	}

	private TableHeaderCell[] getHeaderCells()
	{
		TableHeaderCell id = new TableHeaderCell();
		id.Text = "#";
		TableHeaderCell name = new TableHeaderCell();
		name.Text = "Name";
		TableHeaderCell phoneNr = new TableHeaderCell();
		phoneNr.Text = "Phone No";
		TableHeaderCell ticketId = new TableHeaderCell();
		ticketId.Text = "Ticket id";
		TableHeaderCell[] cells = new TableHeaderCell[] {id, name, phoneNr, 
			ticketId};

		return cells;
	}
}